package cn.yibao.interviewtest;

import cn.yibao.interviewtest.pojo.User;
import io.swagger.models.auth.In;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;
import java.util.UUID;

public class test01 {
    int sum = 0;
    public int test(int n){
        if(n==1 || n==2){
            return 1;
        }
        if(n>=3){
            sum = test(n-2)+test(n-1);
        }
        return sum;
    }
    @Test
    void contextLoads() {
        test01 test = new test01();
        int result = test.test(5);
        System.out.println(result);
    }

    @Test
    public void test02(){
        int count = 0;
        for (int i = 101; i < 200; i+=2) {
            boolean b = false;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if(i%j==0){
                    b=false;
                    break;
                }else {
                    b=true;
                }
            }
            if(b){
                count++;
                System.out.println(i);
            }
        }
        System.out.println("count:"+count);
    }

    @Test
    public void test03(){
        int a = 200;
        System.out.println(Math.sqrt(a));
    }

    @Test
    public void test04(){
        int a=0,b=0,c=0;
        int n=400;
        for (int i = 0; i < n; i++) {
            a = i/100;
            b = i%100/10;
            c = i%10;
            if(a*a*a+b*b*b+c*c*c==i){
                System.out.println("水仙花数为："+i);
            }
        }
    }


    public int test05(int n){
        int sum = 0;
        if(n==1){
            return 1;
        }else {
            sum = n*test05(n-1);
        }
        return sum;
    }

    @Test
    public void test06(){
        System.out.println(test05(5));
        System.out.println(test07());
        System.out.println(test08());
    }

    public long test07(){
        long a = 0;
        long b = 1;
        for (int i = 1; i <=20 ; i++) {
            b = b*i;
            a += b;
        }
        return a;
    }

    @Test
    public double test08(){
        int x = 2,y=1,z;
        double sum = 0;
        for (int i = 0; i <=20; i++) {
            System.out.print(x+"/"+y+"+");
            sum = sum + (double)x/y;
            z = y;
            y = x;
            x = x+z;
        }
        return sum;
    }

    @Test
    public void teset09(){
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j <= i; j++) {
                System.out.print(i+"*"+j+"="+i*j+",");
            }
            System.out.println();
        }
    }

    @Test
    public void test10(){
        String date_;
        byte a = 1;
        short d = 2;
        long g = 4L;
        float i = 5F;
        double k = 2.0;
        char m = 7;
        double v = 2F;
        float x = 2.5F;
        double y = 3.3;
        byte A = 1;
        System.out.println((int)0.4/2);
        System.out.println(v);
        StringBuffer stringBuffer = new StringBuffer().append("accp");
        StringBuffer stringBuffer1 = new StringBuffer("acc");
        String str = 18+"";

        str.length();
        stringBuffer.length();

    }


    public int test11(int n){
        int sum = 0;
        if(n==1){
            return 1;
        }
        sum = n*test11(n-1);
        return sum;
    }
    @Test
    public void test12(){
        int n = 5;
        System.out.println(test11(n));
    }
    @Test
    public void test13(){
        int count =0;
        for (int i = 101; i < 200; i+=2) {
            boolean falg = true;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i%j==0){
                    falg = false;
                }
            }
            if(falg){
                count++;
                System.out.println(i);
            }
        }
        System.out.println(count);
    }

    @Test
    public void test14(){
        int a,b,c;
        for (int i = 100; i < 999; i++) {
            a = i/100;
            b=i/10%10;
            c=i%10;
            if(a*a*a+b*b*b+c*c*c==i){
                System.out.println(i);
            }
        }
    }

    @Test
    public void test15(){
        int n = 125;
        System.out.print("n=");
        for (int i = 2; i < n+1; i++) {
            while (n%i==0&&n!=i){
                n/=i;
                System.out.print(i+"*");
            }
            if(n==i){
                System.out.print(i);
            }
        }
    }

    @Test
    public void test29(){
        int n = 125;
        System.out.print("n=");
        for (int i = 2; i < n+1; i++) {
            while (n%i==0&&n!=i){
                n/=i;
                System.out.print(i+"*");
            }
            if(n==i){
                System.out.print(i);
            }
        }
    }

    @Test
    public void test16(){
        System.out.print("请输入成绩：");
//        Scanner input = new Scanner(System.in);
        int score = 90;
        System.out.println("您属于："+(score>=90?"A级":(score>=60?"B级":"C级")));
    }

    @Test
    public void test17(){
        int n = 80,m=40;
        int temp = 1;
        int yshu = 1;
        int bshu = n*m;
        if(m>n){
            temp = n;
            n = m;
            m = temp;
        }
        while (m != 0) {
            temp = n%m;
            n = m;
            m =temp;
        }

        yshu = n;
        bshu = bshu/n;
        System.out.println("最大公约数："+yshu+"最小公倍数："+bshu);
    }
    @Test
    public void test18(){
        String str = UUID.randomUUID().toString();
        char a ;
        int numbercout = 0;
        int stringcount = 0;
        int othercount = 0;
        for (int i = 0; i < str.length(); i++) {
            a = str.charAt(i);
            if(a>=48&&a<=57){
                numbercout++;
                continue;
            }
            if((a>=65&&a<=90)||(a>=97&&a<=122)){
                stringcount++;
                continue;
            }
            othercount++;
        }
        System.out.println("UUID："+str);
        System.out.println("数字个数为："+numbercout);
        System.out.println("字符个数为："+stringcount);
        System.out.println("其他个数为："+othercount);
    }

    public int test20(int n,int m){
        int sum = 1;
        if(n==1){
            return m;
        }
        for (int i = 0; i < n; i++) {
            sum = sum*m;
        }
        return sum+test20(n-1,m);
    }
    @Test
    public void test21(){
        int n = 5;
        int m = 2;
        int i = test20(n, m);
        System.out.println(i);
    }


    public int test22(){
        int a = 1;
        try {
            a = 2;
            System.out.println("try");
            System.out.println(1/0);
            return a;
        } catch (Exception e) {
            a = 3;
            System.out.println("catch");
            return a;
        }
        finally {
            a = 4;
            System.out.println("finally");
            return a;
        }
    }

    @Test
    public void test23(){
        System.out.println(test22());
    }

    @Test
    public void test24(){
        int[] a = {1,6,3,2,87,0,3,65,87,3,21,67};
        Arrays.sort(a,0,8);
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i]+",");
        }
        System.out.print(a[a.length-1]);
    }

    @Test
    public void test25(){
        int[] a = {1,6,3,2,87,0,3,65,87,3,21,67,65};
        for (int i = 0; i < a.length-1; i++) {
            for (int j = i+1; j < a.length; j++) {
                if(a[i]>a[j]){
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i]+",");
        }
        System.out.print(a[a.length-1]);
    }

    @Test
    public void test26(){
        int[] a = {1,6,3,2,87,0,3,65,87,3,21,67,65};
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length-1-i; j++) {
                if(a[j]>a[j+1]){
                    int temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i]+",");
        }
        System.out.print(a[a.length-1]);
    }

    @Test
    public void test27(){
        int[] a = {1,6,3,2,87,0,3,65,87,3,21,67,65};
        for (int i = 1; i < a.length; i++) {
            int val = a[i];
            int j = i;
            while (j>0 && val<a[j-1]){
                a[j] = a[j-1];
                j--;
            }
            a[j] = val;
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i]+",");
        }
        System.out.print(a[a.length-1]);
    }

    @Test
    public void test(){
        int[] a = {1,6,3,2,87,0,3,65,87,3,21,67,65};
        Arrays.sort(a);
        System.out.println(Arrays.toString(a));
        int low = 0;
        int high = a.length-1;
        int min = (low+high)/2;
        int val = 66;
        while (a[min]!=val){
            if(val>a[min]){
                low = min;
                min = (low+high)/2;
            }
            if(val<a[min]){
                high = min;
                min = (low+high)/2;
            }
            if(low+1==high){
                System.out.println("没有这个数");
                break;
            }
        }
        System.out.println(a[min]);
        System.out.println("min:"+min);
        System.out.println("low:"+low+"high:"+high);
    }
    @Test
    public void test28(){
        int a[] = new int[]{1,3,45};
    }

    @Test
    public void test30(){
        int a = 20;
        switch (a){
            default :
                System.out.println("其他");
            case 5:
                System.out.println(5);
                break;
            case 10:
                System.out.println(10);
                break;
            case 15:
                System.out.println(15);
                break;

        }
    }

    @Test
    public void test31(){
        String s1 = new String("Hello");
        String s2 = new String("Hello");
        System.out.println(s1==s2);
        String s3 = "Hello";
        String s4 = "Hello";
        System.out.println(s3==s4);
        s1=s3;s2=s4;
        System.out.println(s1==s2);

    }
    @Test
    public void test32(){
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 2; j++) {
                if(j==1){
                    continue;
                }
                System.out.println(j+"and"+i);
            }
        }
    }

    //冒泡排序
    @Test
    public void test33(){
        int a[] = {93,42,26,245,7,217,43,4326,17,25,16,2752,3,4,5,2,26,26,7};
        int temp;
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length-1-i; j++) {
                if(a[j]>a[j+1]){
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(a));
    }

    //选择排序
    @Test
    public void test34(){
        int a[] = {93,42,26,245,7,217,43,4326,17,25,16,2752,3,4,5,2,26,26,7};
        int temp;
        for (int i = 0; i < a.length; i++) {
            for (int j = i; j < a.length; j++) {
                if (a[i]>a[j]){
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(a));
    }

    //插入排序
    @Test
    public void test35(){
        int a[] = {93,42,26,245,7,217,43,4326,17,25,16,2752,3,4,5,2,26,26,7};
        int temp;
        for (int i = 1; i < a.length; i++) {
            int val = a[i];
            int j = i;
            while(j>0 && a[j-1]>val){
                a[j] = a[j-1];
                j--;
            }
            a[j] = val;
        }
        System.out.println(Arrays.toString(a));
    }

    @Test
    public void test36(){
        int a[] = new int[1000];
        for (int i = 0; i < a.length; i++) {
            a[i] = i;
        }
        a[899]=202;
        Arrays.sort(a);
        for (int i = 0; i < a.length; i++) {
            int val = a[i];
            a[i] = -1;
            int val2 = test37(a,val);
            if(val2!=-1){
                System.out.println("相同的数字为："+a[val2]);
                break;
            }
        }
    }

    public int test37(int[] a,int val){
        int high = a.length-1;
        int low = 0;
        int mid = (high+low)/2;
        while (low<=high){
            if(val == a[mid]){
                return mid;
            }
            if(a[mid]>val){
                high=mid-1;
                mid = (high+low)/2;
                System.out.println("mid:"+mid);
            }
            if(a[mid]<val){
                low = mid+1;
                mid = (high+low)/2;
                System.out.println("mid:"+mid);
            }
        }
        System.out.println("mid:"+mid);
        return -1;
    }

    @Test
    public void test38(){
        int value = (int)(Math.random()*Integer.MAX_VALUE+1);
        String str = Integer.toBinaryString(value);
        if(str.length()<32){
            for (int i = 0; i <= 32-str.length(); i++) {
                str = "0"+str;
            }
        }
        int a[] = new int[32];
        for (int i = 0; i < 32; i++) {
            a[i] = Integer.parseInt(String.valueOf(str.charAt(i)));

        }
        System.out.println(Arrays.toString(a));
    }

    //测试父类子类构造函数，静态代码块，非静态代码块的执行顺序
    @Test
    public void test39(){
        User user = new User();

    }

    public int test40(int monthnum){
        if(monthnum==1||monthnum==2){
            return 1;
        }else{
            return test(monthnum-2)+test40(monthnum-1);
        }
    }

    @Test
    public void test41(){
        System.out.println(test40(8));
    }

    @Test
    public void test42(){
        int a = 1;
        String b = "2";
        String s = String.valueOf(a);
        int i = Integer.parseInt(b);
    }


    public int test43(int n){
        int sum = 0;
        if(n==1 || n==2){
            System.out.println(1);
            return 1;
        }
        if(n>=3){
            sum = test(n-2)+test(n-1);
        }
        System.out.println(sum);
        return sum;
    }

    @Test
    public void test44(){
        System.out.println(test43(5));
    }

    @Test
    public void test45(){
        int count = 0;
        for (int i = 101; i < 200; i+=2) {
            boolean falg = false;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if(i%j==0){
                    falg = true;
                    System.out.println(i);
                    break;
                }
            }
            if(falg){
                count++;
            }
            System.out.println(count);
        }
    }

    @Test
    public void test46(){
        int[] a = new int[5];
        int b[] = new int[5];
        int[] c = {1,2,3,4,5};
        int d[] = {1,2,3,4,5};
        int[] e = new int[]{1,2,3,4,5};
        int f[] = new int[]{1,2,3,4,5};
    }


}
